(define-module (emacs eglot)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix build-system emacs)
  #:use-module (guix packages)
  #:use-module (gnu packages emacs)
  #:use-module (gnu packages emacs-xyz)
  #:use-module (gnu packages mail)
  #:use-module (guix download))

(define-public emacs-jsonrpc
(package
  (name "emacs-jsonrpc")
  (version "1.0.6")
  (source
    (origin
      (method url-fetch)
      (uri (string-append
             "https://elpa.gnu.org/packages/jsonrpc-"
             version
             ".el"))
      (sha256
        (base32
          "13a19smz8cksv6fgcyxb111csvagkp07z5nl4imyp5b23asgl70p"))))
  (build-system emacs-build-system)
  (home-page
    "http://elpa.gnu.org/packages/jsonrpc.html")
  (synopsis "JSON-RPC library")
  (description
    "This library implements the JSONRPC 2.0 specification as described
in http://www.jsonrpc.org/.  As the name suggests, JSONRPC is a
generic Remote Procedure Call protocol designed around JSON
objects.  To learn how to write JSONRPC programs with this library,
see Info node `(elisp)JSONRPC'.\"

This library was originally extracted from eglot.el, an Emacs LSP
client, which you should see for an example usage.")
  (license license:gpl3+)))


(define-public emacs-eglot
(package
  (name "emacs-eglot")
  (version "1.1")
  (source
    (origin
      (method url-fetch)
      (uri (string-append
             "https://elpa.gnu.org/packages/eglot-"
             version
             ".tar"))
      (sha256
        (base32
          "01h4wh87lrd9l50y20gjjkgg760v8ixvbcb3q8jykl29989zw62y"))))
  (build-system emacs-build-system)
  (propagated-inputs
    `(("emacs-jsonrpc" ,emacs-jsonrpc)))
  (home-page "https://github.com/joaotavora/eglot")
  (synopsis
    "Client for Language Server Protocol (LSP) servers")
  (description
    "Simply M-x eglot should be enough to get you started, but here's a
little info (see the accompanying README.md or the URL for more).

M-x eglot starts a server via a shell-command guessed from
`eglot-server-programs', using the current major-mode (for whatever
language you're programming in) as a hint.  If it can't guess, it
prompts you in the mini-buffer for these things.  Actually, the
server needen't be locally started: you can connect to a running
server via TCP by entering a <host:port> syntax.

Anyway, if the connection is successful, you should see an `eglot'
indicator pop up in your mode-line.  More importantly, this means
current *and future* file buffers of that major mode *inside your
current project* automatically become \\\"managed\\\" by the LSP
server, i.e.  information about their contents is exchanged
periodically to provide enhanced code analysis via
`xref-find-definitions', `flymake-mode', `eldoc-mode',
`completion-at-point', among others.

To \"unmanage\" these buffers, shutdown the server with M-x
eglot-shutdown.

You can also do:

  (add-hook 'foo-mode-hook 'eglot-ensure)

To attempt to start an eglot session automatically everytime a
foo-mode buffer is visited.")
  (license license:gpl3+)))

